<script language="javascript">
	jQuery(document).ready(function(){
		$('#ParentID').change(function(){
			var catid = $('#ParentID').val() ;
			$.post(url+"product/get_level", {'catid':catid}, function(data){
				$('#level').val(parseInt(data)+1) ;
			});
		});
	});
</script>
<?=form_open('product/editcat/'.$this->uri->segment(3),array('id'=>'adminform'));?>
<input type="hidden" id="level" name="level" value="<?=$rs->Level?>" />
<table class="form">
   <tr>
      <td class="w150 required label">Tên danh mục</td>
      <td><input type="text" name="CategoryName" id="title" class="w300 validate[required] text-input" value="<?=$rs->CategoryName?>"></td>
   </tr>
   <tr>
      <td class="label">Danh mục</td>
      <td><select name="ParentID" id="ParentID">
            <option value="0">Là danh mục gốc</option>
            <?
            	foreach($listmaincat as $cat):
						 $listsub1 = $this->product->check_parentid($cat->CategoryID);
			 	?>
            <option value="<?=$cat->CategoryID?>" <?=($rs->ParentID == $cat->CategoryID)?'selected="selected"':'';?>>
            <?=$cat->CategoryName?>
            </option>
            <? 
					if(count($listsub1) > 0){
						foreach($listsub1 as $sub1):
				?>
            <option value="<?=$sub1->CategoryID?>" <?=($rs->ParentID == $sub1->CategoryID)?'selected="selected"':'';?>>¦&nbsp;
            <?=$cat->CategoryName?>
            &nbsp;¦&nbsp;
            <?=$sub1->CategoryName?>
            </option>
            <? 
						// level 3
						$listsub2 = $this->product->check_parentid($sub1->CategoryID);
						if(count($listsub2) > 0){
							foreach($listsub2 as $sub2):
								if($rs->ParentID == $sub2->CategoryID)
									echo '<option value="'.$sub2->CategoryID.'" selected="selected">¦&nbsp;&nbsp;'.$cat->CategoryName.' ¦ '.$sub1->CategoryName.' ¦ '.$sub2->CategoryName.'</option>' ;
								else
									echo '<option value="'.$sub2->CategoryID.'">¦&nbsp;&nbsp;'.$cat->CategoryName.' ¦ '.$sub1->CategoryName.' ¦ '.$sub2->CategoryName.'</option>' ;
							endforeach ;
						} // end level 3
					endforeach ;
				}
				endforeach;
				?>
         </select></td>
   </tr>
   <tr>
      <td class="label">Trang chủ</td>
      <td><input type="checkbox" name="IsMainMenu" value="1" <? if($rs->IsMainMenu==1){echo 'checked="checked"';}?>></td>
   </tr>
   <tr>
      <td class="label">Kích hoạt</td>
      <td><input type="checkbox" name="bl_active" value="1" <? if($rs->IsActive==1){echo 'checked="checked"';}?>></td>
   </tr>
   <tr>
      <td></td>
      <td class="footer"><input type="submit" name="bt_submit" class="capnhat"></td>
   </tr>
</table>
<?=form_close();?>
